package com.nowcoder.community.utils;

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * @Author: shuhuang
 * @description: 在存储用户信息的时候为了避免并发产生的冲突问题，而采取的线程隔离
 * @Date: 2022/10/12 19:09
 * @Version java version 1.8
 */
@Component
public class HostHolder {
    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }
}
